package com.kltn.zigo.data.insert;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.kltn.zigo.data.IP;
import com.kltn.zigo.process.JSONParser;

public class CommentInsert {
	JSONParser jsonParser = new JSONParser();
    
    // url to get all DetailUtilityPlace list
    private static String url_insert_comment = IP.get_IP() + IP.get_path_service() + "insert_comment.php";
    private static final String TAG_SUCCESS = "success";
    String place_id;
    String user_id_zing;
    String detail_comment;
    int type_comment;
    
    public CommentInsert(String PlaceId, String UserIdZing, String DetailComment, int TypeComment)
    {
    	place_id = PlaceId;
    	user_id_zing = UserIdZing;
    	detail_comment = DetailComment;
    	type_comment = TypeComment;
    }
    
    public void InsertComment()
    {
    	List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("place_id", place_id));
        params.add(new BasicNameValuePair("user_id_zing", user_id_zing));
        params.add(new BasicNameValuePair("detail_comment", detail_comment));
        params.add(new BasicNameValuePair("type", Integer.toString(type_comment)));
        
        JSONObject json = jsonParser.makeHttpRequest(url_insert_comment, "POST", params);

        // check log cat fro response
        Log.d("Create Response", json.toString());
        
        // check for success tag
        try {
            int success = json.getInt(TAG_SUCCESS);

            if (success == 1) {
                // successfully created placex
                //Intent i = new Intent(activity.getApplicationContext(), ListPlaceActivity.class);
                //activity.startActivity(i);

                // closing this screen
                //activity.finish();
                
            } else {
                // failed to create place
            	
            	
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
	}
}
